<?php
namespace app\protocol\commands;

class MulCommand extends BaseCommand
{
    public function execute($params, $connection): string
    {
        $args = $this->parseParams($params);
        $this->validateArgumentCount($args, 2, self::getUsage());

        $x = $this->validateNumeric($args[0], '第一个参数');
        $y = $this->validateNumeric($args[1], '第二个参数');

        $result = $x * $y;

        // 如果是整数则返回整数，否则保留小数
        return $result == (int)$result ? (string)(int)$result : (string)$result;
    }

    public static function getDescription(): string
    {
        return '乘法运算: mul <x> <y>';
    }

    public static function getUsage(): string
    {
        return 'mul 3 4';
    }
}